package com.example.ui.fragment;


import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import com.example.administrator.sharker_demo.R;
import com.example.models.data.Study.StudyRecyclerviewData;
import com.example.models.data.ResponseData;
import com.example.models.data.Study.StudyListCourseData;
import com.example.models.data.Study.StudyListTryData;
import com.example.models.data.Study.StudyTopicData;
import com.example.network.RetrofitHelper;
import com.example.ui.activity.MainActivity;
import com.example.ui.adapter.ItemOnclick;
import com.example.ui.adapter.StudyRecyclerviewAdapter;
import com.example.utils.StudyUtils;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import static com.example.App.getAllFragment;
import static com.example.App.getInstance;

/**
 * 董建业  时间:2017/4/10.
 * <p>
 * 学习界面
 */

public class Studyfragment extends TransitionFragment implements ItemOnclick, StudyUtils.InternetData {


    private RecyclerView recyclerView;
    private StudyUtils studyUtils;

    @Override
    public int getlayoutid() {
        return R.layout.fragment_study;
    }

    @Override
    protected void initview(View view) {
        recyclerView = (RecyclerView) view.findViewById(R.id.study_recyclerview);
    }

    @Override
    protected void requestdata() {
        studyUtils = new StudyUtils();
        studyUtils.setInternetdata(this,true);
        studyUtils.getlisttrydata();
    }

    @Override
    public void OnClick(int position, String s) {
        MainActivity activity = (MainActivity) getActivity();
        if (position == 1 || position == 5 || position == 9) {
            activity.setAlldatatype(position);
            activity.setfragmentview(new AllDataFragment());
        } else {
            activity.setfragmentview(new DetailsFragment());
        }
        getAllFragment().add(this);
    }

    @Override
    public void data(ArrayList<StudyRecyclerviewData> listdata) {
        final GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3);
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                int type = recyclerView.getAdapter().getItemViewType(position);
                if (type == 1 || type == 4 || type == 0) {
                    return gridLayoutManager.getSpanCount();
                } else {//内容布局
                    return 1;//占用3/1
                }
            }
        });
        StudyRecyclerviewAdapter studyRecyclerviewAdapter = new StudyRecyclerviewAdapter(getContext(), listdata);
        studyRecyclerviewAdapter.setItemOnclick(this);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setLayoutManager(gridLayoutManager);
        recyclerView.setAdapter(studyRecyclerviewAdapter);
    }

    @Override
    public void returndata(ArrayList<StudyRecyclerviewData> listdata) {

    }
}
